package com.aaa.car.service.impl;

import com.aaa.car.dao.TbBrandDao;
import com.aaa.car.entity.TbBrand;
import com.aaa.car.entity.TbCarType;
import com.aaa.car.service.TbBrandService;
import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 品牌表
 * (TbBrand)表服务实现类
 *
 * @author makejava
 * @since 2020-11-21 11:28:07
 */
@Service("tbBrandService")
public class TbBrandServiceImpl implements TbBrandService {
    @Resource
    private TbBrandDao tbBrandDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbBrand queryById(Long id) {
        return this.tbBrandDao.queryById(id);
    }

    /**
     * 查询车辆品牌
     *
     * @param pageNo
     * @param pageSize
     * @param tbBrand
     * @return
     */
    @Override
    public Result queryCarBrand(Integer pageNo, Integer pageSize, TbBrand tbBrand) {
        //分页
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<TbBrand> pageInfo = new PageInfo<TbBrand>(tbBrandDao.queryAll(tbBrand));
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),pageInfo);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<TbBrand> queryAllByLimit(int offset, int limit) {
        return this.tbBrandDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tbBrand 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(TbBrand tbBrand) {
        return this.tbBrandDao.insert(tbBrand);
    }

    /**
     * 修改数据
     *
     * @param tbBrand 实例对象
     * @return 实例对象
     */
    @Override
    public TbBrand update(TbBrand tbBrand) {
        this.tbBrandDao.update(tbBrand);
        return this.queryById(tbBrand.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tbBrandDao.deleteById(id) > 0;
    }
}